package com.frogs.ucenter.v1.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.frogs.framework.base.web.BaseController3;
import com.frogs.system.web.api.response.FailResponse;
import com.frogs.system.web.api.response.Response;
import com.frogs.system.web.exception.AppBaseException;
import com.frogs.ucenter.v1.request.UserHonorAddRequest;
import com.frogs.ucenter.v1.request.UserHonorListRequest;
import com.frogs.ucenter.v1.service.UserHonorService;
import com.frogs.ucenter.v1.util.ApiConstants;

@Controller(ApiConstants.VERSION + "userHonorController")
@RequestMapping("/" + ApiConstants.VERSION )
public class UserHonorController extends BaseController3 {
	
	private static final String ROOT = "/user/honor";
	
	private static final String USER_HONOR_ADD = ROOT + "/add";
	
	private static final String USER_HONOR_LIST = ROOT + "/list";
	
	@Resource(name=ApiConstants.VERSION+"userHonorService")
	private UserHonorService userHonorService;
	
	
	/**
	 * 新增用户荣誉值
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(USER_HONOR_ADD)
	public Response userHonorAdd(HttpServletRequest request, ModelMap model) {
		Response response = null ; 
		try{
			UserHonorAddRequest req = new UserHonorAddRequest();
			req.parse(request);
			response = userHonorService.insertUserHonorScore(req.getUserId(), req.getHonorType(), req.getHonorScore(), req.getDetail(), req.getTargetUserId(), req.getOpenPlatformId(),true);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	@RequestMapping(USER_HONOR_LIST)
	public Response userHonorList(HttpServletRequest request, ModelMap model) {
		Response response = null ; 
		try{
			UserHonorListRequest req = new UserHonorListRequest();
			req.parse(request);
			response = userHonorService.getUserHonorList(req);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}


	
	
}
